var express = require('express');
var router = express.Router();
const storesApi =require("../api/stores")

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});

//新增店铺
router.post('/addStores', async function (req, res, next) {
    const stores = req.body;
    const data = await storesApi.add(stores);
    res.send(data);
});

//获取店铺列表
router.get('/getStores', async function (req, res, next) {
    const{ curPage, eachPage }=req.query;
    const data = await storesApi.get({ curPage, eachPage });
    res.send(data);
});
//修改店铺信息
router.post('/editStores', async function (req, res, next) {
 const result= await storesApi.editStores(req.body);
  res.send(result);
});
//删除店铺
router.delete('/deleteStores', async function (req, res, next) {
  const { _id } = req.query;
  const data = await storesApi.deleteStores({ _id });
  res.send(data);
});
//查询店铺
router.get('/searchStores', async function (req, res, next) {
  const stores=req.query;
  const data = await storesApi.searchStores(stores );
  res.send(data);
});


module.exports = router;